home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / tex-k / tex-k-archive.past / tex-k-archive.gz / tex-k-archive / 000425_peterh@prz.tu-berlin.de_Wed Mar 23 15:48:52 1994.msg < prev    next >
Internet Message Format  |  1994-10-11  |  3KB

  1. Received: from mailgzrz.TU-Berlin.DE by cs.umb.edu with SMTP id AA19875
  2.   (5.65c/IDA-1.4.4 for <tex-k@cs.umb.edu>); Wed, 23 Mar 1994 14:43:47 -0500
  3. Received: from tubkom.prz.tu-berlin.de by mailgzrz.TU-Berlin.DE (5.65c/ZRZ-MX)
  4.           for <tex-k@cs.umb.edu>
  5.       id AA23723; Wed, 23 Mar 1994 14:50:09 +0100
  6. Received: from king.prz.tu-berlin.de by tubkom.prz.tu-berlin.de with SMTP
  7.     (16.6/15.6) id AA13343; Wed, 23 Mar 94 14:48:52 +0100
  8. Date: Wed, 23 Mar 94 14:48:52 +0100
  9. From: Peter Hofmann <peterh@prz.tu-berlin.de>
  10. Posted-Date: Wed, 23 Mar 94 14:48:52 +0100
  11. Received-Date: Wed, 23 Mar 94 14:48:52 +0100
  12. Message-Id: <9403231348.AA13343@tubkom.prz.tu-berlin.de>
  13. Received: by king.prz.tu-berlin.de.tu-berlin.de (4.1/SMI-4.1)
  14.     id AA27647; Wed, 23 Mar 94 14:48:51 +0100
  15. Subject: Bug in dvipsk-5.528a/kpathsea
  16. To: tex-k@cs.umb.edu
  17.  
  18. Hi,
  19.  
  20. I've found a memory deallocation bug in dvipsk-5.528a/kpathsea/db.c:
  21.  
  22. str_list_type
  23. kpse_db_search P3C(const_string, name,  const_string, path_elt,  boolean, all)
  24. {
  25.   static hash_table_type db;
  26.   str_list_type ret;
  27.   string *db_dirs;
  28.   boolean done = false;
  29.   
  30.   /* Hash up the database if this is the first call.  */
  31.   if (db.size == 0)
  32.     {
  33.       db = hash_create (7603); /* What the heck, sparse is ok.  */
  34.       db_build (&db);
  35.     }
  36.   
  37.   /* Look up NAME.  */
  38.   db_dirs = hash_lookup (db, name); << A
  39.  
  40.   ret = str_list_init (); /* Some old compilers ...  */
  41.   
  42.   while (!done && db_dirs && *db_dirs)
  43.     {
  44.       string db_file = concat (*db_dirs, name);
  45.       
  46.       if (match (db_file, path_elt) && kpse_readable_file (db_file))
  47.         {
  48.           str_list_add (&ret, db_file);
  49.           if (!all) done = true;
  50.         }
  51.       else
  52.         free (db_file);
  53.       
  54.       /* On to the next directory, if any.  */
  55.       db_dirs++;            << B
  56.     }
  57.   
  58.   /* This is just the space for the pointers, not the strings.  */
  59.     
  60.   return ret;
  61. }
  62.  
  63. db_dirs is allocated at point A, it is changed at point B. It points now
  64. to a memory address never allocated. At point C db_dir is freed. This is
  65. the point where the segmentation fault occurs.
  66.  
  67. My solution:
  68.  
  69.   string save_db_dirs;
  70.   ....
  71.   save_db_dirs = db_dirs = hash_lookup (db, name); << A
  72.   ....
  73.   if (db_dirs && *db_dirs) free (save_db_dirs);  << C
  74.  
  75. Peter
  76.  
  77. --
  78. Peter Hofmann                     e-mail: peterh@prz.tu-berlin.de
  79. Technical University Berlin
  80. Str. des 17. Juni 135             Tel. ++49-(0)30-314-21701
  81. D-10623 Berlin, Germany